use std::io;
use std::collections::HashMap;

pub fn test1() {
    println!("请输入几组数字，用逗号隔开：");
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let v: Vec<&str> = input.trim().split(',').collect();
    let vec:Vec<i32> = v.iter().map(|x| x.parse().unwrap()).collect();
    println!("{:?}", vec);
    println!("average:{}",get_average(vec));
    let mut hm =HashMap::new();
    hm.insert(String::from("value"), "v");
    hm.entry(String::from("value")).or_insert_with(||{
        input.push_str("s");
        "input"
        });
}
fn get_average(v: Vec<i32>) -> i32 {
    let mut num = 0;
    for i in v.iter() {
        num += *i;
    }

    num / (v.len() as i32)
}
fn get_middle(v:Vec<i32>)->i32{
    (v.len() as i32)/2
}
fn get_mode(v:Vec<i32>)->i32{
    let mut h:HashMap<i32,i32> = HashMap::new();
    for i in v.iter(){
        if h.contains_key(i){
            let mut value = 
                match h.get(i){
                    Some(n)=>*n,
                    None => 0,
                };
            value+=1;
            h.insert(*i, value);
        }else{
            h.insert(*i, 1);
        }
    }
    let mut values:Vec<i32> = Vec::new();
    let mut keys:Vec<i32> =Vec::new();
    for (k,va) in h{
        keys.push(k);
        values.push(va);
    }
    values.sort();
    values[0]
}